﻿using System;
using System.Data.Common;
using System.Data.SqlClient;
using System.Web;
using Easy.BLL;
using Easy.Operation;

namespace Easy.Web.Service.Data
{
    /// <summary>
    /// GetN2NData 的摘要说明
    /// </summary>
    public class GetN2NData : BaseHttpHandler
    {
        public override void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string returnValue = "";

            //string aid = context.Request["aid"];    //主记录guid
            //string mid = context.Request["mid"];    //中间表记录guid
            string EntityA = context.Request["EntityA"];
            string EntityB = context.Request["EntityB"];
            string EntityM = context.Request["EntityM"];
            string aid = context.Request["linkentityid"];
            string filterData = context.Request["filter"];  //查询条件
            string order = context.Request["order"];    //排序字段
            string viewname = context.Request["viewname"];  //视图

            if (filterData == null) filterData = "";
            if (viewname == null) viewname = "DefaultView";
            int pageNum = 0;    //当前页码
            if (context.Request["pagenum"] != null)
            {
                pageNum = int.Parse(context.Request["pagenum"].ToString());
            }
            int pageSize = 50;  //每页记录数
            if (context.Request["pagesize"] != null)
            {
                pageSize = int.Parse(context.Request["pagesize"].ToString());
            }

            //if ( (("RD_" + EntityA + "_" + EntityB) == EntityM || ("RD_" + EntityB + "_" + EntityA) == EntityM))
            //{
            DataService service = new DataService(EntityB, this.CurrentUserId);
            returnValue = service.RetrieveMultipleN2NByView(order, filterData, viewname, EntityA, EntityM, new Guid(aid), pageNum, pageSize);

            context.Response.Write(returnValue);
            
        }

       
    }
}